<?php

session_start();
require_once('include/db.inc.php');
include('include/cfg.inc.php');
$db = new DbManager();
$db->connect(DBHOST, DBUSER, DBPWD, true, true, DBNAME, "");
$list = $db->query_select("cllg_entity", NULL);
$_SESSION['user'] = "eliu";
$_SESSION['clave'] = "adminadmin";
$_SESSION['entidad'] = "2";
$cols = array("B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
$campos = "select NAME from cllg_tablefield WHERE TABLE_NAME = 'cllg_student' AND STATUS=1 order by FK_TAB,ORD";
$lsFlds = $db->query_toArray($campos);
$c = 0;
$matriz = array();
$s = false;

foreach ($lsFlds as $v) {
    if ($c >= count($cols)) {
        $c = -1;
        $s = true;
    }
    $k = !$s ? $cols[$c] : ("A" . $cols[$c]);
    $val = $v["NAME"];
    $matriz[$k] = $val;

    $pk = "CONVERT(A , SIGNED)";
    $insert = "insert into cllg_table_valuebyfield(PK_RECORD,VALUE,FK_TABLEFIELD) 
					select $pk as PK,$k as VALOR,'$val' as campo from migracion
				";
    $db->query($insert);
    echo $insert;
    echo "<BR>";
    $c++;
}
//print_r($matriz);
?>